package com.dkd.day20250711;

import java.io.*;
import java.util.HashSet;
import java.util.Set;

public class Main10 {
    public static void main(String[] args) throws IOException {
        //依据用户输入的单词前缀，从已输入的英文语句中联想出用户想输入的单词，按字典序输出联想到的单词序列，
        //如果联想不到，请输出用户输入的单词前缀。
        //注意：
        //
        //英文单词联想时，区分大小写
        //缩略形式如”don’t”，判定为两个单词，”don”和”t”
        //输出的单词序列，不能有重复单词，且只能是英文单词，不能有标点符号

        //获取数据
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String sentence = br.readLine();
        String pre = br.readLine();

        solve(sentence, pre);
    }


    public static void solve(String Sentence, String pre) {
        //将sentence转化为词表
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < Sentence.length(); i++) {
            char c = Sentence.charAt(i);
            if ('a' <= c && c <= 'z' || 'A' <= c && c <= 'Z') {
                sb.append(c);
            } else {
                sb.append(" ");
            }
        }
        String[] words = sb.toString().split(" ");


        //排序和去重
        Set<String> wordSet = new HashSet<String>();
        for (String word : words) {
            wordSet.add(word);
        }

        //查找是否存在
        StringBuilder answer = new StringBuilder();
        for (String word : wordSet) {
            if (word.startsWith(pre)) {
                answer.append(word).append(" ");

            }
        }
            if (answer.length() > 0) {
                System.out.println(answer);
            } else {
                System.out.println(pre);
            }

        }


    }
